package com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.service.impl;

import com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.entity.bo.SensitiveWordParam;
import com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.entity.vo.SensitiveResult;
import com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.entity.vo.SingleResult;
import com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.handler.SensitiveWordChain;
import com.gitee.jjnnzb.designpatterninspring.business.sensitive_word.service.SensitiveWordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Jjn
 * @since 2023/8/11 11:36
 */
@Service
@RequiredArgsConstructor
public class SensitiveWordServiceImpl implements SensitiveWordService {
    
    private final SensitiveWordChain sensitiveWordChain;
    
    
    @Override
    @SuppressWarnings("unchecked")
    public SensitiveResult handleSensitiveWord(SensitiveWordParam sensitiveWordParam) {
        Map<String, Object> map = new HashMap<>();
        map.put("content", sensitiveWordParam.getContent());
        List<SingleResult> results = new ArrayList<>();
        map.put("result", results);
        sensitiveWordChain.filter(map);
        return new SensitiveResult()
                .setData((List<SingleResult>) map.get("result"))
                .setContent((String) map.get("content"));
    }
}
